<?php

namespace App\SubApps\Account\Models;



use App\Abstracts\Traits\ModelAppendStatusNameTrait;
use App\SubApps\Account\Traits\ModelSetConnectionMysqlTrait;
use Hilaoyu\LaravelExtend\Extensions\Files\Traits\ModelWithFilesTrait;
use Hilaoyu\LaravelExtend\Model;
use Hilaoyu\LaravelExtend\Services\AccessControl\Traits\ModelWithAccessControlFilterTrait;

class OauthAppsModel extends Model
{

    use ModelSetConnectionMysqlTrait;
    protected $table = 'oauth_apps';


    protected $fillable = [
        'domain',
        'name',
        'secret',
        'return_url',
        'summary',
        'status',
        'logo',
    ];

    protected $casts = [
        'return_url' => 'array'
    ];


    use ModelAppendStatusNameTrait;


    public function getValidationRules()
    {
        $rules =  [
            'domain' => 'required|string|unique:' . static::getTableCon() . ',domain,' . $this->getOriginalKey() . ',' . static::getPkName(),
            'name' => 'required|string',
            'secret' => 'required|string|size:16',
        ];

        return $rules;
    }


    use ModelWithFilesTrait;
    protected function _getSettingImageFields(): array
    {
        return [
            'logo' => 'oauth_logos'
        ];
    }

    use ModelWithAccessControlFilterTrait;
    public function accessGetAccessIdentifier(): string
    {
        return 'oauth_apps';
    }
}
